package com.xiayuanxing.arithmetic.DataStructures.Sort;

import java.util.Arrays;

/**
 * @program: arithmetic
 * @description: 插入排序
 * @author: xia yuan xing
 * @create: 2021-09-24 11:16
 */
public class InsertionSort {

    public static void main(String[] args) {
        int[] array = {-1, 6, 3, 12, 80, -9, -5, -93, 120};
        insertionSort(array);
    }


    /**
     * 插入排序
     * @param array
     */
    public static void insertionSort(int[] array){

        for (int i = 1; i <array.length ; i++) {
            for (int j = i; j >0 ; j--) {
                if (array[j] < array[j - 1]){
                    int temp = array[j -1];
                    array[j -1] = array[j];
                    array[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }
}